/*
 * Copyright (C) 2008 Alessandro Sivieri <alessandro.sivieri@chimera-bellerofonte.eu>.
 *
 *  This file is part of Daex.
 *
 *  Daex is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package eu.chimera_bellerofonte.tesi;

import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;

/**
 * Questa classe definisce un metodo statico per ottenere con maggior
 * praticita' l'istanza del logger utilizzato dalle classi del progetto.
 * Questa classe applica il pattern Singleton.
 * 
 * @see java.util.logging.Logger
 * @author Sivieri Alessandro
 * @author Vitucci Nicola
 * @version 28/apr/07
 */
public class DaexLogger
{
	/**
	 * Nome del logger nel registro di Java
	 */
	public static final String LOG_NAME="daex";
	public static final String LOG_CONF="/eu/chimera_bellerofonte/tesi/logger.conf";
	
	private static Logger logger=null;
	
	/**
	 * Metodo statico per ottenere l'istanza comune del logger del
	 * sistema.
	 * 
	 * @return l'istanza del logger
	 */
	public static Logger getDaexLogger()
	{
		if(logger==null)
		{
			try
			{
				InputStream is=DaexLogger.class.getResourceAsStream(LOG_CONF);
				LogManager.getLogManager().readConfiguration(is);
			}
			catch (Exception e)
			{
				System.out.println("Errore irreversibile nel creare il logger");
				e.printStackTrace();
				System.exit(1);
			}
			logger=Logger.getLogger(LOG_NAME);
			logger.info("Logger creato - DAEx On Java");
			Runtime.getRuntime().addShutdownHook(new Thread()
			{

				/**
				 * @see java.lang.Thread#run()
				 */
				@Override
				public void run()
				{
					logger.info("Esecuzione conclusa.");
				}
				
			});
		}
		return logger;
	}
	
}
